using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_Shop_buyTeam : Member, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected Label Label3;
	protected DropDownList DropDownList1;
	protected TextBox TxtSalerName;
	protected TextBox TxtProductName;
	protected Button QuickSearch;
	protected GridView GridView1;
	private int UserID = 0;
	protected string wherestr = string.Empty;
	private ArrayList al = new ArrayList();
	private IDbDataParameter[] param = null;
	private int type = 0;
	private Shop_Product _product = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_Product m_product
	{
		get
		{
			Shop_Product product;
			if (this._product == null)
			{
				this._product = new Shop_Product(this.conn);
				product = this._product;
			}
			else
			{
				product = this._product;
			}
			return product;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.UserID = base.user.UserID;
		this.type = Convert.ToInt32(this.DropDownList1.SelectedValue);
		if (!base.IsPostBack)
		{
			if (Fetch.Get("action") == "record")
			{
				int iD = Fetch.GetID("productid");
				if (iD == 0)
				{
					this.WriteErrMsg("", Language.Get("Common/LostParam", "productid"), "");
				}
				Shop_Order shop_Order = new Shop_Order(this.conn);
				this.GridView1.DataSource = shop_Order.GetAllTeamOrderForm(iD);
				this.GridView1.DataBind();
				DataTable dataTable = this.conn.GetDataTable("select ProductName from HLShop_Product where ProductID=" + iD);
				this.Label3.Text = dataTable.Rows[0]["ProductName"].ToString() + "——>团购记录";
			}
			else
			{
				this.GridView1.DataSource = this.m_product.GetPrepaidOrder(this.UserID);
				this.GridView1.DataBind();
				this.Label3.Text = "我在团购";
			}
		}
		this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.PageIndexChanging);
	}
	protected void BindList()
	{
		this.QuestString();
		if (this.al.Count > 0)
		{
			this.param = new IDbDataParameter[this.al.Count];
			this.al.CopyTo(this.param, 0);
		}
		int userID = base.user.UserID;
		if (this.param == null)
		{
			this.GridView1.DataSource = this.m_product.GetBuyerTeamBuyProduct(userID, this.type, this.wherestr, null);
		}
		else
		{
			this.GridView1.DataSource = this.m_product.GetBuyerTeamBuyProduct(userID, this.type, this.wherestr, this.param);
		}
		this.GridView1.DataBind();
	}
	protected void QuestString()
	{
		this.wherestr = string.Empty;
		string text = this.TxtSalerName.Text;
		if (text != string.Empty)
		{
			this.wherestr += "and SalerID in(Select UserID From [HL_User] where UserName  like '%' + @SalerName + '%') ";
			this.al.Add(this.conn.CreateParameter("@SalerName", DbType.String, text.Trim()));
		}
		string text2 = this.TxtProductName.Text;
		if (text2 != string.Empty)
		{
			this.wherestr += "and ProductName like '%' + @ProductName + '%' ";
			this.al.Add(this.conn.CreateParameter("@ProductName", DbType.String, text2.Trim()));
		}
		if (this.wherestr != string.Empty)
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "Where");
		}
	}
	protected void QuickSearch_OnClick(object sender, EventArgs e)
	{
		this.BindList();
	}
	protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindList();
	}
	protected void DropMoment_OnSelectedIndexChanged(object sender, EventArgs e)
	{
		this.BindList();
	}
	public string ShowProductName(string ProductID)
	{
		string result = "";
		DataTable dataTable = this.conn.GetDataTable("select ProductName from HLShop_Product where ProductID=" + ProductID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			result = dataTable.Rows[0]["ProductName"].ToString();
		}
		return result;
	}
	public string TeamRecord(string Teameffect)
	{
		string result;
		if (Teameffect != null && !string.IsNullOrEmpty(Teameffect))
		{
			if (int.Parse(Teameffect) == 1)
			{
				result = "团购历史记录";
			}
			else
			{
				result = "正在团购中记录";
			}
		}
		else
		{
			result = "正在团购中记录";
		}
		return result;
	}
}
